<template>
	<view class="container padding-top-sm">
		<view class="bg-white margin-top-sm" v-if='type'>
			<view class="solid-bottom text-13 flex justify-between align-center padding">
				<view class="text-333 flex-sub text-bold"> 原支付密码 </view>
				<input maxlength='6' type="password" v-model="oldPassWord" value="" class="text-13 flex-treble"
					placeholder="请输入原支付密码" />
			</view>
			<view class="solid-bottom text-13 flex justify-between align-center padding">
				<view class="text-333 flex-sub text-bold"> 新支付密码 </view>
				<input maxlength='6' type="password" v-model="newPassWord" value="" class="text-13 flex-treble"
					placeholder="请输入新支付密码" />
			</view>
			<view class="solid-bottom text-13 flex justify-between align-center padding">
				<view class="text-333 flex-sub text-bold">确认新密码 </view>
				<input maxlength='6' type="password" v-model="reNewPassWord" value="" class="text-13 flex-treble" placeholder="确认新密码" />
			</view>

		
		</view>
		
		
		<view class="bg-white margin-top-sm" v-else>
			<view class="solid-bottom text-13 flex justify-between align-center padding">
				<view class="text-333 flex-sub text-bold"> 支付密码 </view>
				<input maxlength='6' type="password" v-model="newPassWord" value="" class="text-13 flex-treble"
					placeholder="请输入支付密码" />
			</view>
			
			
		</view>
		<view class="padding">
			<button class="btn" @click="submit">提交</button>

		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				reNewPassWord: '',
				oldPassWord: '',
				newPassWord: '',
				type:true
			}
		},
		onShow() {
			const user = uni.getStorageSync('userInfo')
			if(user.payPassword){
				this.type = true
			}else{
				this.type = false
			}
			console.log(this.type)
		},
		methods: {
			async submit() {
				const {
					reNewPassWord,
					oldPassWord,
					newPassWord
				} = this
				
				if(!this.type){
					if(!newPassWord){
						return this.$util.msg('请输入支付密码')
					}
					var CusBase64 = require('@/common/js/base64.js');
				     var result2 = CusBase64.CusBASE64.encoder(newPassWord);
					 var data  ={newPassWord:result2,userId:uni.getStorageSync('userId')}
				}else{
					if(!oldPassWord){
						return this.$util.msg('请输入原支付密码')
					}
					if(!newPassWord){
						return this.$util.msg('请输入新支付密码')
					}
					console.log(newPassWord,oldPassWord)
					
					if(reNewPassWord!=newPassWord){
						return this.$util.msg('确认密码与新支付密码不一致')
					}
					var CusBase64 = require('@/common/js/base64.js');
					//函数调用
					var result1=CusBase64.CusBASE64.encoder(oldPassWord);
					var result2 = CusBase64.CusBASE64.encoder(newPassWord);
					var data  ={oldPassWord:result1,newPassWord:result2,userId:uni.getStorageSync('userId')}
				}
				const [err,rs] = await this.$get(this.$api.setPayPassWord,data)
				if(rs){
					this.$util.msg(rs.message)
					setTimeout(()=>{
					   uni.navigateBack({
					   	
					   })	
					},1000)
				}
			}
		}
	}
</script>

<style scoped>
	.btn {
		background: linear-gradient(90deg, #F16347, #EE0979);
		padding: 20rpx 0;
		color: #fff;
		margin-top: 60rpx;
		font-size: 28rpx;
	}
</style>
